package com.example.springbootwebserviceproxy.pool;

import com.example.springbootwebserviceproxy.model.SOAPServiceProxyDefinition;
import com.example.springbootwebserviceproxy.model.WebServiceBeanDefinition;
import com.example.springbootwebserviceproxy.util.AOSPDefinitionBuilderUtil;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * SOAPServicePool.
 *
 * @author <a href='mailto:likeguo@apache.com'> likeguo </a>
 */
@Component
public class SOAPServicePool {
    String protocol = "http";
    String host = "www.webxml.com.cn";
    private final Map<String, WebServiceBeanDefinition> pool = new ConcurrentHashMap<>();
    
    @PostConstruct
    public void init() {
        add("DomesticAirline", "webservices/DomesticAirline.asmx");
        add("ChinaStockSmallImageWS", "webservices/ChinaStockSmallImageWS.asmx");
        add("qqOnlineWebService", "/webservices/qqOnlineWebService.asmx");
        add("ValidateEmailWebService", "WebServices/ValidateEmailWebService.asmx");
        add("WeatherWebService", "/WebServices/WeatherWebService.asmx");
        
    }
    
    private void add(String proxy, String target) {
        pool.put(proxy, AOSPDefinitionBuilderUtil.build(SOAPServiceProxyDefinition.builder()
                .protocol(protocol)
                .host(host)
                .proxyUri(proxy)
                .targetUri(target)
                .build()));
    }
    
    public WebServiceBeanDefinition getServiceByName(String name) {
        return pool.get(name);
    }
    
}
